package com.zsc.tool.serial;

import org.apache.commons.codec.binary.Base64;
import org.nustaq.serialization.FSTConfiguration;

/**
 * Created by xbkaishui on 17/3/7.
 */
public class Serializer {


    static ThreadLocal<FSTConfiguration> conf = new ThreadLocal() {
        public FSTConfiguration initialValue() {
//            return FSTConfiguration.createDefaultConfiguration();
                        return FSTConfiguration.createJsonConfiguration(false,false);
        }
    };


    public static String serializer(Object obj) {
        return Base64.encodeBase64String(serializerToBytes(obj));
    }

    public static byte[] serializerToBytes(Object obj) {
        return conf.get().asByteArray(obj);
    }

    public static Object deSerializer(String obj) {
        return conf.get().asObject(Base64.decodeBase64(obj));
    }


}
